function __loadResources(path){
  return new Promise((resolve,reject)=>{
    $.ajax({
      url:`images/${path}`,
      dataType:'json',
      success(json){
        let res = {};
        let counter = 0,total = 0;
        for (let name in json) {
          total++;
          let oImage = new Image();
          //图片加载完成
          oImage.onload = function(ev){
            counter++;
            res[name] = {
              image:this,
              frame:json[name].frame
            };
            if (counter == total) {
              resolve(res); //返回资源
            }
          };
          //图片加载出错
          oImage.onerror = function(){
            reject();
          };
          oImage.src = `images/${json[name].src}`; //加载图片
        }
      },
      error(err){
        reject(err);
      }
    });
  });
}

async function loadResources(){
  //需要加载的资源配置文件
  const src = {
    bottom:"bottom.json",  //按钮
    bullet:"bullet.json",  //子弹
    cannon:"cannon.json",  //炮
    coin:"coin.json",      //金币
    fish:"fish.json",      //鱼
    number:"number.json",  //数字
    web:"web.json"         //网格
  };

  let imgs = {};
  try {
    for (let name in src) {
      imgs[name] = await __loadResources(src[name]);
    }
    window.__g_resources = imgs; //全局变量，减少参数的传递
  } catch (e) {
    throw e;
  }
}
